正确安装

众所周知,Linux系统自带的repo是不会自动更新每个软件的最新版本(基本都是比较靠后的稳定版),所以无法通过yum方式安装MySQL的高级版本。所以我们需要先安装带有当前可用的mysql5系列社区版资源的rpm包。

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

查看mysql安装的相关资源

yum repolist enabled | grep "mysql.*-community.*"

安装mysql

yum -y install mysql-community-server

启动mysql

systemctl start mysqld

初始化设置root用户的用户名密码,已经是否允许远程连接

mysql_secure_installation

创建新的用户名和密码

create user username identified by password

给用户分配权限

GRANT privileges ON databasename.tablename TO 'username'@'host'

grant all privileges on *.* to 'username'@'localhost' identified by 'password'

删除权限

REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'localhost';

分配指定库的权限

GRANT ALL PRIVILEGES ON database1.* TO 'username'@'localhost' IDENTIFIED BY 'password';

分配指定操作的权限

GRANT SELECT, UPDATE ON database1.* TO 'username'@'localhost' IDENTIFIED BY 'password';

刷新权限

FLUSH PRIVILEGES

删除用户

DROP USER username@localhost;

设置默认的编码

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示

character_set_server=utf8
init_connect='SET NAMES utf8'

重启mysql

systemctl restart mysqld

更新用户的密码

SET PASSWORD FOR 'username'@'localhost' = PASSWORD("123456");

或者

update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";

wupengyu
1.8k 声望166 粉丝

写作是为了更好的思考